﻿using Lingmeng.EntityFrameworkCore.core;
using Lingmeng.EntityFrameworkCore.Core.Base;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace Lingmeng.EntityFrameworkCore
{
    /// <summary>
    /// efcore核心扩展
    /// </summary>
    public static class LingmengEntityFrameWorkExtension
    {
        public static IServiceCollection AddEntityFrameworkCore<IDbContext>(this IServiceCollection services,
            Action<DbContextOptionsBuilder> options=null,ServiceLifetime lifetime=ServiceLifetime.Scoped)
            where IDbContext:MasterDbContext<IDbContext>
        {
            services.AddDbContext<IDbContext>(options,lifetime);
            services.AddTransient(typeof(IUnitOfWork), typeof(UnitOfWork<IDbContext>));
            return services;
        }
    }
}
